package com.qingge.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qingge.springboot.controller.dto.CourseTeacherVo;
import com.qingge.springboot.controller.dto.UserDTO;
import com.qingge.springboot.entity.Student;
import com.qingge.springboot.entity.Teacher;
import com.qingge.springboot.mapper.StudentMapper;
import com.qingge.springboot.service.StudentService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【student】的数据库操作Service实现
* @createDate 2022-12-15 20:57:16
*/
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student>
implements StudentService {

    @Override
    public UserDTO login(String username, String password) {
        LambdaQueryWrapper<Student> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Student::getStuno,username);
        lambdaQueryWrapper.eq(Student::getPassword,password);
        Student student = this.baseMapper.selectOne(lambdaQueryWrapper);
        UserDTO userDTO = new UserDTO();
        if(student!=null){
            BeanUtils.copyProperties(student,userDTO);
            userDTO.setUsername(student.getStuno().toString());
            userDTO.setUsername(student.getStuName());
            userDTO.setNickname(student.getStuName());
        }
        return userDTO;
    }

    @Override
    public List<CourseTeacherVo> selectClassCourseByStuId(Integer stuId) {
        List<CourseTeacherVo> courseTeacherVos = this.baseMapper.selectClassCourseByStuId(stuId);
        return courseTeacherVos;
    }
}
